import { defineStore } from "pinia";

interface IState {
  menus: UserMenu[];
  username: string;
}

export const useUserStore = defineStore("user", {
  state: (): IState => {
    return {
      menus: [],
      username: "",
    };
  },
  getters: {
    permissions(this: IState): string[] {
      return this.menus.map((item) => item.name);
    },
    parentMenus(this: IState) {
      return this.menus.filter((item) => item.parentId === 0);
    },
  },
  actions: {
    clear(this: IState) {
      this.menus = [];
      this.username = "";
    },
  },
});
